package com.hzjy.manage.controller;

import java.util.List;

import com.hzjy.manage.service.impl.HzjyTradeNewsServiceImpl;
import com.hzjy.manage.vo.HzjyTradeNews;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hzjy.common.annotation.Log;
import com.hzjy.common.core.controller.BaseController;
import com.hzjy.common.core.domain.AjaxResult;
import com.hzjy.common.enums.BusinessType;

import com.hzjy.common.utils.poi.ExcelUtil;
import com.hzjy.common.core.page.TableDataInfo;

/**
 * 行业资讯（新闻）Controller
 * 
 * @author hzjy
 * @date 2020-08-14
 */
@RestController
@RequestMapping("/manage/news")
public class HzjyTradeNewsController extends BaseController
{
    @Autowired
    private HzjyTradeNewsServiceImpl hzjyTradeNewsService;

    /**
     * 查询行业资讯（新闻）列表
     */
    @PreAuthorize("@ss.hasPermi('manage:news:list')")
    @GetMapping("/list")
    public TableDataInfo list(HzjyTradeNews hzjyTradeNews)
    {
        startPage();
        List<HzjyTradeNews> list = hzjyTradeNewsService.selectHzjyTradeNewsList(hzjyTradeNews);
        return getDataTable(list);
    }

    /**
     * 导出行业资讯（新闻）列表
     */
    @PreAuthorize("@ss.hasPermi('manage:news:export')")
    @Log(title = "行业资讯（新闻）", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HzjyTradeNews hzjyTradeNews)
    {
        List<HzjyTradeNews> list = hzjyTradeNewsService.selectHzjyTradeNewsList(hzjyTradeNews);
        ExcelUtil<HzjyTradeNews> util = new ExcelUtil<HzjyTradeNews>(HzjyTradeNews.class);
        return util.exportExcel(list, "news");
    }

    /**
     * 获取行业资讯（新闻）详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:news:query')")
    @GetMapping(value = "/{tradeNewsId}")
    public AjaxResult getInfo(@PathVariable("tradeNewsId") Long tradeNewsId)
    {
        return AjaxResult.success(hzjyTradeNewsService.selectHzjyTradeNewsById(tradeNewsId));
    }

    /**
     * 新增行业资讯（新闻）
     */
    @PreAuthorize("@ss.hasPermi('manage:news:add')")
    @Log(title = "行业资讯（新闻）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HzjyTradeNews hzjyTradeNews)
    {
        return toAjax(hzjyTradeNewsService.insertHzjyTradeNews(hzjyTradeNews));
    }

    /**
     * 修改行业资讯（新闻）
     */
    @PreAuthorize("@ss.hasPermi('manage:news:edit')")
    @Log(title = "行业资讯（新闻）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HzjyTradeNews hzjyTradeNews)
    {
        return toAjax(hzjyTradeNewsService.updateHzjyTradeNews(hzjyTradeNews));
    }

    /**
     * 删除行业资讯（新闻）
     */
    @PreAuthorize("@ss.hasPermi('manage:news:remove')")
    @Log(title = "行业资讯（新闻）", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tradeNewsIds}")
    public AjaxResult remove(@PathVariable Long[] tradeNewsIds)
    {
        return toAjax(hzjyTradeNewsService.deleteHzjyTradeNewsByIds(tradeNewsIds));
    }
    /**
     * 修改行业资讯状态
     */
    @PreAuthorize("@ss.hasPermi('manage:news:edit')")
    @Log(title = "行业资讯（新闻）", businessType = BusinessType.UPDATE)
    @PutMapping("/changeState")
    public AjaxResult changeState(@RequestBody HzjyTradeNews hzjyTradeNews){
        return toAjax(hzjyTradeNewsService.updateNewsState(hzjyTradeNews));
    }
}
